﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
    using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.CBO.Pub.Controller;
    using UFIDA.U9.SM.ForecastOrder;
    using UFSoft.UBF.AopFrame;
    using UFSoft.UBF.Util.Context;

    /// <summary>
    /// ForecastOrderApproveSV partial 
    /// </summary>	
    public partial class ForecastOrderApproveSV
    {
        internal BaseStrategy Select()
        {
			return new ForecastOrderApproveSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class ForecastOrderApproveSVImpementStrategy : BaseStrategy
	{
		public ForecastOrderApproveSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			ForecastOrderApproveSV bpObj = (ForecastOrderApproveSV)obj;

            try
            {
                if (bpObj.Data == null || bpObj.Data.Count == 0)
                    throw new Exception("传入参数为空");
                List<CommonArchiveDataDTOData> retlist = new List<CommonArchiveDataDTOData>();

                foreach (var dto in bpObj.Data)
                {
                    ForecastOrder entity = ForecastOrder.Finder.Find($"DocNo='{dto.Code}'");
                    if (entity == null)
                    {
                        throw new Exception($"单号:[{dto.Code}]不存在!");
                    }
                    else
                    {
                        ForecastOrderBase.ApproveDoc(entity);
                        CommonArchiveDataDTOData retdto = new CommonArchiveDataDTOData();
                        retdto.Code = entity.DocNo;
                        retdto.ID= entity.ID;
                        retlist.Add(retdto);
                    }
                }
                return ResultUtils.success(bpObj, bpObj.Data, retlist);
            }
            catch (Exception ex)
            {
                return ResultUtils.error(bpObj, bpObj.Data, ex);
            }
        }		
	}

	#endregion
	
	
}